<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>jxls - Collections samples</title>
    <style type="text/css" media="all">
      @import url("../css/maven-base.css");
      @import url("../css/maven-theme.css");
      @import url("../css/site.css");
    </style>
    <link rel="stylesheet" href="../css/print.css" type="text/css" media="print" />
          <meta name="author" content="Leonid Vysochyn" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                  <a href="http://jxls.sourceforge.net" id="bannerLeft">
    
            jXLS
    
            </a>
                          <span id="bannerRight">
    
                                    <img src="http://sourceforge.net/sflogo.php?group_id=141729&type=1" alt="" />
    
            </span>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
    
            <div class="xleft">
        Last Published: 13 Nov 2014
                      </div>
            <div class="xright">            <a href="http://sourceforge.net/projects/jxls" class="externalLink">jXLS on Sourceforge</a>
            
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
    
                   <h5>Overview</h5>
            <ul>
              
    <li class="none">
                    <a href="../index.html">Home</a>
          </li>
              
    <li class="none">
                    <a href="http://sourceforge.net/project/showfiles.php?group_id=141729" class="externalLink">Downloads</a>
          </li>
              
    <li class="none">
                    <a href="../reference/installation.html">Installation</a>
          </li>
          </ul>
              <h5>Reference</h5>
            <ul>
              
    <li class="none">
                    <a href="../reference/simplebeans.html">Simple Beans</a>
          </li>
              
    <li class="none">
                    <a href="../reference/tags.html">Using Tags</a>
          </li>
              
    <li class="none">
                    <a href="../reference/sqlreporting.html">SQL Reporting</a>
          </li>
              
    <li class="none">
                    <a href="../reference/collections.html">Collections</a>
          </li>
              
    <li class="none">
                    <a href="../reference/advancedcollections.html">Advanced Collections</a>
          </li>
              
    <li class="none">
                    <a href="../reference/dynamicsheets.html">Dynamic Sheets</a>
          </li>
              
    <li class="none">
                    <a href="../reference/expressions.html">Using Expressions</a>
          </li>
              
    <li class="none">
                    <a href="../reference/formulas.html">Formulas Notation</a>
          </li>
              
    <li class="none">
                    <a href="../reference/poiaccess.html">POI Objects Access</a>
          </li>
              
    <li class="none">
                    <a href="../reference/columnhiding.html">Column Hiding</a>
          </li>
              
    <li class="none">
                    <a href="../reference/sheetoperations.html">Spreadsheet Operations</a>
          </li>
              
    <li class="none">
                    <a href="../reference/customprocessor.html">Custom Processor</a>
          </li>
              
    <li class="none">
                    <a href="../reference/resultset.html">JDBC ResultSet</a>
          </li>
              
    <li class="none">
                    <a href="../reference/reader.html">XLS Reader</a>
          </li>
          </ul>
              <h5>Samples</h5>
            <ul>
              
    <li class="none">
                    <a href="../samples/tagsample.html">Tags Sample</a>
          </li>
              
    <li class="none">
                    <a href="../samples/chartsample.html">Charts</a>
          </li>
              
    <li class="none">
                    <a href="../samples/reportsample.html">Reporting Sample</a>
          </li>
              
    <li class="none">
              <strong>Collections</strong>
        </li>
              
    <li class="none">
                    <a href="../samples/adjacentlists.html">Adjacent Lists</a>
          </li>
              
    <li class="none">
                    <a href="../samples/dynamicstylesample.html">Dynamic Style</a>
          </li>
              
    <li class="none">
                    <a href="../samples/resultsetsample.html">JDBC ResultSet</a>
          </li>
              
    <li class="none">
                    <a href="../samples/dynamiccolumnssample.html">Dynamic Columns</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="../project-info.html">Project Information</a>
                </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="../images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2><a name="Overview"></a>Overview</h2>
<p>This section contains several examples demonstrating how to export collections with
                <a class="externalLink" href="http://jxls.sourceforge.net">jXLS</a>.
				In all samples we assume there are two Java beans of type
                <a href="departmentbean.html">Department</a> and
                <a href="employeebean.html">Employee</a></p>
</div>
<div class="section"><h2><a name="Simple_collection_export"></a>Simple collection export</h2>
<p>This sample demonstrates how to export a collection of employees. Source code is as following</p>
<div class="source"><pre>
			Collection staff = new HashSet();
		        staff.add(new Employee(&quot;Derek&quot;, 35, 3000, 0.30));
		        staff.add(new Employee(&quot;Elsa&quot;, 28, 1500, 0.15));
		        staff.add(new Employee(&quot;Oleg&quot;, 32, 2300, 0.25));
		        staff.add(new Employee(&quot;Neil&quot;, 34, 2500, 0.00));
		        staff.add(new Employee(&quot;Maria&quot;, 34, 1700, 0.15));
		        staff.add(new Employee(&quot;John&quot;, 35, 2800, 0.20));
		        Map beans = new HashMap();
		        beans.put(&quot;employee&quot;, staff);
		        XLSTransformer transformer = new XLSTransformer();
		        transformer.transformXLS(templateFileName, beans, destFileName);
            </pre>
</div>
<p>Template file screenshot</p>
<img src="../images/employeesTemplateXLS.gif" alt="Screenshot of Employees XLS template file" /><p>You can also download Excel version
                <a href="../xls/employees.xls">employees.xls</a></p>
<p>Output file looks like</p>
<img src="../images/employeesOutputXLS.gif" alt="Screenshot of Employees XLS output" /><p> Excel file
                <a href="../xls/employees_output.xls">employees_output.xls</a></p>
</div>
<div class="section"><h2><a name="Complex_bean_export"></a>Complex bean export</h2>
<p>This sample demonstrates how to export
                <a href="departmentbean.html">Department</a> bean. Source code snippet
            </p>
<div class="source"><pre>
				Department department = new Department(&quot;IT&quot;);
				//...  initialization is skipped here
			        Map beans = new HashMap();
			        beans.put(&quot;department&quot;, department);
			        XLSTransformer transformer = new XLSTransformer();
			        // set grouping of rows for &quot;department.staff&quot; collection 
			        transformer.groupCollection(&quot;department.staff&quot;);
			        transformer.transformXLS(templateFileName, beans, destFileName);
            </pre>
</div>
<p>Here is a template file screenshot </p>
<img src="../images/departmentTemplateXLS.gif" alt="Screenshot of Department XLS template file" /><p>Excel version is here
                <a href="../xls/department.xls">department.xls</a></p>
<p>Using this template we'll get an output like</p>
<img src="../images/departmentOutputXLS.gif" alt="Screenshot of Department XLS output" /><p> Excel is here
                <a href="../xls/department_output.xls">department_output.xls</a></p>
</div>
<div class="section"><h2><a name="Multiple_excel_rows_for_every_collection_item"></a>Multiple excel rows for every collection item</h2>
<p>This sample demonstrates how to export collection with several rows per every collection item. Source code snippet</p>
<div class="source"><pre>
				Department department = new Department(&quot;IT&quot;);
				//...  initialization is skipped here
			        Map beans = new HashMap();
			        beans.put(&quot;department&quot;, department);
			        XLSTransformer transformer = new XLSTransformer();
			        transformer.transformXLS(templateFileName, beans, destFileName);
            </pre>
</div>
<p>Here is a template file screenshot </p>
<img src="../images/multiplelistrowsTemplateXLS.gif" alt="Screenshot of multiplelistrows XLS template file" /><p>See excel file for details
                <a href="../xls/multiplelistrows.xls"> multiplelistrows.xls</a></p>
<p>Using this template we'll get an output like</p>
<img src="../images/multiplelistrowsOutputXLS.gif" alt="Screenshot of multiplelistrows XLS output" /><p> Excel is here
                <a href="../xls/multiplelistrows_output.xls">multiplelistrows_output.xls</a></p>
</div>
<div class="section"><h2><a name="Nested_collections"></a>Nested collections</h2>
<p>This sample demonstrates how to export collections nested in other collections. We export collection of departments and every department contain staff collection. Source code snippet</p>
<div class="source"><pre>
				// create a list of Departments
			        List departments = new ArrayList();
				//... initialization
			        Map beans = new HashMap();
			        beans.put(&quot;departments&quot;, departments);
			        XLSTransformer transformer = new XLSTransformer();
			        transformer.transformXLS(templateFileName, beans, destFileName);
            </pre>
</div>
<p>Template is </p>
<img src="../images/groupingTemplateXLS.gif" alt="Screenshot of grouping XLS template file" /><p>See also xls file
                <a href="../xls/grouping.xls"> grouping.xls</a></p>
<p>Output is </p>
<img src="../images/groupingOutputXLS.gif" alt="Screenshot of grouping XLS output" /><p> Excel is here
                <a href="../xls/grouping_output.xls">grouping_output.xls</a></p>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2005-2014
    
          jXLS Team
          
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
